<%@page import="qldc.pm.tiensu.model.DoiTuongTienSu"%>
<%@page import="qldc.pm.tiensu.service.DoiTuongTienSuLocalServiceUtil"%>
<%@page import="qldc.pm.tiensu.dto.DoiTuongTienSuDTO"%>
<%@page import="com.liferay.portal.kernel.util.StringUtil"%>
<%@page import="qldc.pm.qtht.dmdc.utils.StringUtils"%>
<%@page import="qldc.pm.tiensu.service.TienSuLocalServiceUtil"%>
<%@page import="qldc.pm.tiensu.model.TienSu"%>
<%@page import="com.liferay.portal.kernel.util.Validator"%>
<%@page import="com.liferay.portal.kernel.util.Constants"%>
<%@page import="qldc.pm.tiensu.model.LichSuXoaAnTich"%>
<%@page import="com.liferay.portal.kernel.util.WebKeys"%>
<%@page import="com.liferay.portal.kernel.dao.search.ResultRow"%>

<%@include file="../../init.jsp"%>

<%
	PortletURL redirectURL = renderResponse.createRenderURL();
	redirectURL.setParameter("mvcPath", "/html/view.jsp");
	redirectURL.setParameter("chonChucNangItem", TienSuConstants.QUAN_LY_YEU_CAU_XOA_AN_TICH);

	ResultRow row = (ResultRow) request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
	LichSuXoaAnTich lichSuXoaAnTich = (LichSuXoaAnTich) row.getObject();
	String primKey = String.valueOf(lichSuXoaAnTich.getLichSuXoaAnTichId());
	

	PortletURL inReportURL = renderResponse.createActionURL();
	inReportURL.setParameter(TienSuConstants.ACTION_HANDLER_PARAM, TienSuConstants.QUAN_LY_NGUOI_CO_TIEN_SU);
	inReportURL.setParameter(Constants.ACTION, "xoaAnTich");
	inReportURL.setParameter("redirect", redirectURL.toString());
	inReportURL.setParameter("cmd", TienSuConstants.IN);
	inReportURL.setParameter("lichSuXoaAnTichId", primKey);
	
	String tienSuId = StringUtil.valueOf(lichSuXoaAnTich.getTienSuId());
	String soDinhDanhCaNhan = "";
	TienSu tienSu = TienSuLocalServiceUtil.fetchTienSu(lichSuXoaAnTich.getTienSuId());
	if (Validator.isNotNull(tienSu)){
		long doiTuongTienSuId = tienSu.getDoiTuongTienSuId();
		DoiTuongTienSu doiTuongTienSu = DoiTuongTienSuLocalServiceUtil.findByDoiTuongTienSuId(doiTuongTienSuId);
		soDinhDanhCaNhan = doiTuongTienSu.getSoDinhDanhCaNhan();
	}
%>

<liferay-ui:icon-menu message="thao-tac">

<%

if (Validator.isNull(lichSuXoaAnTich.getNgayKyDuyetXoaAnTich())){
	
		%>
		<portlet:renderURL var="kyDuyetYeuCauURL">
			<portlet:param name="mvcPath" value="/html/view.jsp" />
				<portlet:param name="chonChucNangItem" value="<%=TienSuConstants.QUAN_LY_YEU_CAU_XOA_AN_TICH %>" />
				<portlet:param name="tabs1" value="xem_chi_tiet_an_tich" />
				<portlet:param name="redirect" value="<%=redirectURL.toString() %>"/>
				<portlet:param name="lichSuXoaAnTichId" value="<%=primKey%>" />
				<portlet:param name="tienSuId" value="<%=String.valueOf(tienSuId) %>"/>
				<portlet:param name="soDinhDanhCaNhan" value="<%=soDinhDanhCaNhan %>" />
		</portlet:renderURL>
		
		<liferay-ui:icon image="export" message="ky-duyet-yeu-cau-xoa-an-tich" url="<%=kyDuyetYeuCauURL.toString() %>" />
		
		<liferay-ui:icon image="print" message="in-yeu-cau-xoa-an-tich" url="<%=\"javascript:\" + \"inDuLieu(\'\" + inReportURL.toString() + \"\')\" %>" />
		
		
		<portlet:actionURL var="xoaHoSoURL">
			<portlet:param name="<%=TienSuConstants.ACTION_HANDLER_PARAM%>" value="<%=TienSuConstants.QUAN_LY_NGUOI_CO_TIEN_SU%>" />
			<portlet:param name="<%=Constants.ACTION%>" value="xoaYeuCauXoaAnTich" />
			<portlet:param name="redirect" value="<%=redirectURL.toString()%>" />
			<portlet:param name="lichSuXoaAnTichId" value="<%=primKey%>" />
		</portlet:actionURL>
	
	<liferay-ui:icon-delete message="bo-yeu-cau-xoa-an-tich" confirmation="ban-muon-xoa-ho-so-xoa-an-tich-nay" url="<%=xoaHoSoURL.toString()%>" />
		
	<%-- <liferay-ui:icon image="delete" message="bo-yeu-cau-xoa-an-tich" url="<%= \"javascript:\" + renderResponse.getNamespace()+ \"confirmBoXoaAnTich\"+\"('\"+xoaHoSoURL.toString()+\"')\" %>" /> --%>

<%} else {
	%>
	
	<portlet:renderURL var="xemYeuCauURL">
				<portlet:param name="mvcPath" value="/html/view.jsp" />
				<portlet:param name="chonChucNangItem" value="<%=TienSuConstants.QUAN_LY_YEU_CAU_XOA_AN_TICH %>" />
				<portlet:param name="tabs1" value="xem_chi_tiet_an_tich" />
				<portlet:param name="redirect" value="<%=redirectURL.toString() %>"/>
				<portlet:param name="lichSuXoaAnTichId" value="<%=primKey%>" />
				<portlet:param name="tienSuId" value="<%=String.valueOf(tienSuId) %>"/>
				<portlet:param name="soDinhDanhCaNhan" value="<%=soDinhDanhCaNhan %>" />
	</portlet:renderURL>

	<liferay-ui:icon image="view" message="xem-chi-tiet" url="<%=xemYeuCauURL.toString()%>" />
	
	<liferay-ui:icon image="print" message="in-yeu-cau-xoa-an-tich" url="<%=\"javascript:\" + \"inDuLieu(\'\" + inReportURL.toString() + \"\')\" %>" />
	
<%}
	%>

	
	

</liferay-ui:icon-menu>


<script>

function <portlet:namespace/>confirmBoXoaAnTich(action){
	var co = '<liferay-ui:message key="co" />';
	var khong ='<liferay-ui:message key="khong"/>';
	var message = '<liferay-ui:message key="confirm-bo-xoa-an-tich" />';
	console.log('action ',action);
	showPopupConfirm(message,[co, khong], 
			function(index) {
				if (index == 0){
					
					window.location.href = action;
				}
			}
	);
}


	function inDuLieu(url) {
		var form = $("<form>").attr({
			action : url,
			method : "POST",
			target : "_blank"
		});
		form.appendTo(document.body).submit();

	}
</script>